package com.igogogo.web.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.igogogo.model.entity.Ig_Admin;
import com.igogogo.model.service.Ig_AdminService;
import com.igogogo.utils.ResoureceUtils;
import com.igogogo.utils.ResultJson;
import com.igogogo.utils.WordUtils;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@RestController
@RequestMapping(value = "admin")
@Api(value = "Ig_AdminController", description = "管理员相关接口")
public class Ig_AdminController {

	@Autowired
	private Ig_AdminService adminService;

	@ApiOperation(value = "登录")
	@RequestMapping(value = "/login", method = RequestMethod.POST)
	public ResultJson login(@RequestBody Ig_Admin admin) {
		ResultJson json = new ResultJson();
		admin.setAdminpwd(
				WordUtils.md5(admin.getAdminname() + admin.getAdminpwd() + ResoureceUtils.getPropValue("salt")));
		Ig_Admin returnModel = adminService.login(admin);
		if (returnModel != null) {
			json.setMsgcode(200);
			json.setMsginfo("success");
			json.setResult(returnModel);
		}
		return json;
	}

	@ApiOperation(value = "注册")
	@RequestMapping(value = "/regist", method = RequestMethod.POST)
	public ResultJson regist(@RequestBody Ig_Admin admin) {
		ResultJson json = new ResultJson();
		admin.setAdminpwd(
				WordUtils.md5(admin.getAdminname() + admin.getAdminpwd() + ResoureceUtils.getPropValue("salt")));
		if (adminService.regist(admin) > 0) {
			json.setMsgcode(200);
			json.setMsginfo("success");
		}
		return json;
	}

}
